//
//  SISSEscrowAccountShowViewModel.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/25.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSEscrowAccountShowViewModel.h"
#import "SISSContractCheckLabelCell.h"
#import "SISSContractTextFillInCell.h"

@implementation SISSEscrowAccountShowViewModel

- (NSString *)plistName {
    return @"EscrowAccountApplyInfoArray";
}


- (void)registContractClass:(UITableView *)tableView {
    [super registContractClass:tableView];
    [tableView registerClass:[SISSContractTextFillInCell class] forCellReuseIdentifier:contractTextFillInCellReuseID];
    [tableView registerClass:[SISSContractCheckLabelCell class] forCellReuseIdentifier:contractCheckLabelCellReuseID];
}

- (UITableViewCell *)getCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    
    NSInteger cellType = self.dataArr[indexPath.section][indexPath.row].cellType;
    if (cellType == 11) {
        SISSContractTextFillInCell *cell = [tableView dequeueReusableCellWithIdentifier:contractTextFillInCellReuseID forIndexPath:indexPath];
        cell.contractModel = self.dataArr[indexPath.section][indexPath.row];
        return cell;
    } else if (cellType == 20) {
        SISSContractCheckLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:contractCheckLabelCellReuseID forIndexPath:indexPath];
        cell.contractModel = self.dataArr[indexPath.section][indexPath.row];
        return cell;
    }
    
    return [super getCell:tableView indexPath:indexPath];
}

- (UIView *)getViewHeaderInSection:(NSInteger)section {
    
    SISSBaseView *headerView = [[SISSBaseView alloc] init];
    headerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    UILabel *label = [[UILabel alloc] init];
    label.textColor = COLOR(0x334A60);
    label.font = [UIFont systemFontOfSize:16];
    [headerView addSubview:label];
    
    CGFloat margin = 8.0;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView).offset(2 * margin);
        make.centerY.equalTo(headerView);
    }];
    
    NSArray *headerTextArr = @[@"甲方（卖方）", @"乙方（买方）", @"", @"资金划转条件", @"达成交易时，划转至卖方交易的资金结算账户", @"达成交易时，利息划转至帐户", @"交易资金退回的条件是(满足以下条件之一即可)", @"其他约定:"];
    
    label.text = headerTextArr[section];
    
    return headerView;
}

- (CGFloat)getHeightForHeaderInSection:(NSInteger)section {
    if (section == 2) {
        return 16;
    } else {
        return 44;
    }
}


- (void)assignmentWithEscrowAccountInfoModel:(SISSEscrowAccountInfoModel *)escrowAccountInfoModel {
    NSDictionary *infoDict = [escrowAccountInfoModel yy_modelToJSONObject];
    for (NSInteger section = 0; section < self.dataArr.count; section++) {
        
        for (NSInteger idx = 0; idx < self.dataArr[section].count; idx++) {
            
            SISSContractModel *obj = self.dataArr[section][idx];
            
            if (section == 2 && idx == 0) {
                obj.array = @[escrowAccountInfoModel.amount];
            } else if (section == 3 && idx == 0) {
                if ([escrowAccountInfoModel.term integerValue] == 1) {
                    obj.isChecked = YES;
                } else if ([escrowAccountInfoModel.term integerValue] == 2) {
                    obj.isCheckedTwo = YES;
                } else if ([escrowAccountInfoModel.term integerValue] == 3) {
                    obj.isCheckedThree = YES;
                }
                
            } else if (section == 7 && idx == 0) {
                obj.array = @[escrowAccountInfoModel.month];
                
            } else {
                obj.rightStr = infoDict[obj.propertyKey] != nil ? [NSString stringWithFormat:@"%@",infoDict[obj.propertyKey]] : @" ";;
            }
        }
    }
    
//    [self.tableView reloadData];
}

@end
